﻿
@{
    ViewData["Title"] = "Form";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<link href="~/plugins/zTree_v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <div class="ibox">
        <div class="ibox-title">
            <h3 class="m-t-none m-b">通讯录</h3>
        </div>
        <div class="ibox-content">
            <form class="form form-horizontal" id="form" autocomplete="off">
                <input type="hidden" name="id" id="id" value="0">
                <div class="form-group">
                    <label class="col-sm-3 control-label required">姓名：</label>
                    <div class="col-sm-4">
                        <input type="text" name="real_name" id="real_name" value="" class="form-control" data-rule="required;" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">部门：</label>
                    <div class="col-sm-8" id="deptDiv">
                        <textarea id="parentDept" style="width:300px;height:50px;overflow:hidden;" textLabel="jasontext" type="text" readonly></textarea>
                        <input type="hidden" name="dept_id" id="dept_id" value="0" class="form-control">
                        <input type="hidden" name="department_name" id="department_name" value="" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">职务：</label>
                    <div class="col-sm-4">
                        <input type="text" name="work_job" id="work_job" value="" class="form-control" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">办公电话：</label>
                    <div class="col-sm-4" id="leaderDiv">
                        <input type="text" name="inner_tel" id="inner_tel" value="" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">手机号码：</label>
                    <div class="col-sm-4">
                        <input type="number" name="mobile" id="mobile" value="" class="form-control" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">个人资料：</label>
                    <div class="col-sm-4">
                        <textarea name="profile" id="profile" cols="60" rows="5"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">联系地址：</label>
                    <div class="col-sm-4">
                        <textarea name="address" id="address" cols="60" rows="5"></textarea>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">排序：</label>
                    <div class="col-sm-4" id="leaderDiv">
                        <input type="number" name="sort_num" id="sort_num" value="0" class="form-control"/>
                    </div>
                </div>
                <div class="footerbar">
                    <div class="col-sm-12 col-sm-offset-3">
                        <button class="btn btn-primary" type="submit">保存内容</button>
                        <button class="btn btn-white" type="button" onclick="cancel()">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

@section scripts{
    <script src="~/plugins/zTree_v3/js/jquery.ztree.all.min.js"></script>
    <script src="~/plugins/selectTree/MultipleTreeSelect.js"></script>
    <script>
        var ue,deptSelectedIds=[];
        $(function () {
            var id = jutils.getQueryParam("id");
            $("#id").val(id);

            $('#form').validator({
                stopOnError: false,
                timely: 2,
                theme: "yellow_right",
                valid: function (form) {
                    jutils.ajaxPost("/work/addressbook/Save", $(form).serialize(), function (res) {
                        if (res.status) {
                            cancel();
                        }
                    })

                }
            });
            loadData();
        });


        function loadData() {
            var id = $("#id").val();
            jutils.ajaxGet('/work/addressbook/getmodel', { id: id }, function (res) {
                if (id !== '0') {
                    var model = res.data.model;
                    $('#form').initFormData(model);
                    $('#parentDept').attr('checks', model.dept_id);
                }

                initSelectTree(res.data.depts);
            });




        }
        function initSelectTree(treeNodes) {
            var defaults = {
                callback: {
                    onCheck: zTreeOnCheck
                },
                chkStyle: "radio",
                zNodes: treeNodes,
                height: 333   // 默认自定义下拉框高度
            }

            $("#parentDept").drawMultipleTree(defaults);
        }
        function zTreeOnCheck(treeNodes) {
            // console.log(treeNodes);

            // alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
            //selectDepartments.length = 0;
            if (treeNodes.length > 0) {
                var parentId = treeNodes[0].id;
                $('#dept_id').val(parentId);
                $('#department_name').val(treeNodes[0].name);
            } else {
                $('#dept_id').val(0);
                $('#department_name').val('');
            }

            //console.log(selectDepartments);
        };
        function cancel() {
            jutils.back();
        }
    </script>
}



